<!DOCTYPE html>
<html class="um landscape min-width-240px min-width-320px min-width-480px min-width-768px min-width-1024px">
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="target-densitydpi=device-dpi, width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta name="copyright" content="http://www.appcms.org" />
<link rel="stylesheet" type="text/css" href="skin/base.css">
<link rel="stylesheet" type="text/css" href="skin/btn.css">
<link rel="stylesheet" type="text/css" href="skin/form.css">
<link rel="stylesheet" type="text/css" href="skin/editor.css">
<script src="js/zy_control.js"></script>
<script src="js/zy_click.js"></script>
<script src="js/config.js"></script>
<script src="js/common.js"></script>
<script src="js/cursorControl.js"></script>
<style>
	.form .pic_c li{};
	.form .video_c li{};
</style>
</head>
<body>
<div id="main">
	<div class="form">
    	<div class="items">
	        <div class="item">
	            	<div class="txt">
						<textarea class="textarea" id="editdiv" name="editdiv" maxlength="240" placeholder="分享我的吃玩乐新鲜事～" onkeypress="getRealLen(this.value);" oninput="getRealLen(this.value);"></textarea>
						<div class="em">
							<div class="l" id="address" onclick="getadds();"></div>
							<div class="r" id="words">240</div>
						</div>
					</div>
	        </div>
        </div>
		
		<div id="menus">
            <div class="putbtns">
           		
                <div class="ld pic act" ontouchstart="zy_touch('act')" onclick="btntab('pic');" id="pic_id"></div>
				<div class="ld video" ontouchstart="zy_touch('act')" onclick="btntab('video');" id="video_id"></div>
				

                <div class="cd">同步到</div>
				<div class="ld sina" id="sina" onclick="share('sina')"></div>
				<div class="ld qqweibo" id="qqweibo" onclick="share('qqweibo')"></div>
            </div>
           
            <ul class="pic_c" id="pic_c_id">
            	<li class="up_add" ontouchstart="zy_touch('act')" onclick="getpic();" id="add_pic"><div></div></li>
            </ul>
			<ul class="pic_c" style="display:none;" id="video_c_id">
            	<li class="up_add" ontouchstart="zy_touch('act')" onclick="getvideo();" id="add_video"><div></div></li>
            </ul>
			
		</div>
    </div>
	
  <!--
  <div class="putvoice d_n" id="voice_c">
    <div class="l"><img src="skin/images/talk/put_voice_l.png" width="50" height="39"><span id="backrecordv"></span></div>
    <div class="r"  ontouchstart="zy_touch('down',backrecord())"><img src="skin/images/talk/put_voice_r.png" width="50" height="39"><span id="backrecord">开始录音</span></div>
  </div>
  <input name="voice" value="" id="voice" type="hidden">

  
  <input name="photos" value="" id="photos" type="hidden">
  <div class="btn" >
    <div class="button"  ontouchstart="zy_touch('down')" onclick="postdata()" >发表说说</div>
  </div>
  -->
  
</div>
</body>
<script>
	zy_init();	
	var isstart=false;
	var isadds = true;
	var Sele = {'sina':false,'qzone':false,'qqweibo':false};
	
	
	var strlen=0;
	var status=true;
	var uplistn=0;
	var uplist = {'type':{},'url':{}};;
	
	
	function getRealLen(str){
		strlen=str.replace(/[^\x00-\xff]/g,'__').length;
		$$('words').innerHTML=parseInt(240-strlen);
		if(strlen>240){			
			$$('editdiv').value=substr(str,240);
		}
	}
	//////////////////////////////////////////////
	
	var sheet = null;
	function createCSS()
	{
		if(!sheet) {
			var style = document.createElement("style");
			document.body.appendChild(style);
			sheet = style.sheet;
		}
		var h =  parseInt(parseInt(window.innerWidth)*0.94/4);
		var pt = parseInt(parseInt(window.innerWidth)*0.06/5);
		var c="height:"+h+"px; margin-top:"+pt+"px;";
		sheet.addRule(".form .pic_c li",c);
	}
	createCSS();
	
	function btntab(t){
		var arr = ['pic','video']
		for(var k in arr){	
			var a = $$(arr[k]+'_id');
			var b = $$(arr[k]+'_c_id');
			if(arr[k]== t){
				a.className = 'ld '+arr[k]+' act';
				b.style.display="block";
				
				/*
				if(arr[k] =='pic'){
					getpic();
				}else if(arr[k] =='video'){
					getvideo();
				}
				*/
			}else{
				a.className='ld '+arr[k];
				b.style.display="none";
			}
		}
	}
	
	function obj2str(obj){
		var _str = '';
		for (var item in obj) {
			_str += obj[item]+'|';
		}
		_str = _str.substr(0, (_str.length - 1));
		return _str;
	}
	
	function getpic(){
		uexWindow.cbActionSheet = function(opId, dt, d){
			var cmd = parseInt(d);
			if(cmd<2){
				if(cmd==1){
					uexImageBrowser.cbPick = function(opCode, dataType, data) {
						uploadImg(data,'pic');
					}
					uexImageBrowser.pick();
				}
				else{
					uexCamera.cbOpen  = function(opCode, dataType, data) {
						uploadImg(data,'pic');
					}
					uexCamera.open(0,80);
				}
			} 
		}
			
		var value = ["拍照上传","本地上传"];
		uexWindow.actionSheet('', '取消', value);
	}

	function uploadImg(dirPath,type){
		uplistn++;
		var pNode = document.getElementById(type+"_c_id");
		var newNode = document.createElement("li");
		newNode.className='uploading';
		newNode.setAttribute("id", type+"_"+uplistn);
		newNode.setAttribute("onclick", "javascript:delNd("+uplistn+",'"+type+"');");
		newNode.setAttribute("ontouchstart", "javascript:zy_touch('act');");

		var reforeNode = document.getElementById("add_"+type);
		if(type=='pic'){
			newNode.innerHTML ='<div><img src="'+dirPath+'" /></div>';
			pNode.insertBefore(newNode,reforeNode);
		}else if(type=='video'){
			var _video = $$('video_c_id').getElementsByTagName("video");
			if (_video.length > 1) {
				uexWindow.alert('', '只能添加一个视频', '关闭');
			}else {
				newNode.innerHTML = '<div><video controls="controls" width="100%" height="100%"  autoplay="autoplay" id="video"  poster="" src="' + dirPath + '" webkit-playsinline /></div>';
				pNode.insertBefore(newNode,reforeNode);
			}
		}else if(type=='voice'){
			newNode.innerHTML ='<div><img src="'+dirPath+'" /></div>';
		}
		
	}
	
	function delNd(id,type){
		uexWindow.cbActionSheet = function(opId, dataType, data)
		{
			if (data == "0") {
				id = parseInt(id);
				removeNode(type+'_'+id);
				delete uplist[type][type+'_'+id];
			}
		}
		var value = ["删除"];
		uexWindow.actionSheet('', '取消', value);
	}

	function getvideo(){
		uexWindow.cbActionSheet = function(opId, dt, wd){
			var cmd = parseInt(wd);
			if(cmd<2){
				if(cmd==1){
					uexFileMgr.cbExplorer = function(opCode, dataType, data){
						//alert(data)
						uploadImg(data,'video');
	                }
					uexFileMgr.explorer('');
				}
				else{
					uexVideo.cbRecord = function(opCode, dataType, data){
	                    alert(data);
						uploadImg(data,'video');
	                };
					uexVideo.record();
				}
			} 
		}
		var value = ["拍摄上传","本地上传"];
		uexWindow.actionSheet('', '取消', value);
	}
	
	function postdata(){
		if (!c_l()) {
			gologin();
			return false;
		}
		var content = trim($$('editdiv').value);
		var address = localStorage['talk_ask_address'];
		var voice = localStorage['talk_ask_voice'];
		if (content == '') {
			uexWindow.alert('', '忘了说点什么～', '关闭');
			return false;
		}
		if (strlen > 240) {
			uexWindow.alert('', '亲，说说太长啦～', '关闭');
			return false;
		}
		
		var k = 0;
		
		localStorage.removeItem("talk_ask_uplist");
		var _photos = $$('pic_c_id').getElementsByTagName("img");
		if (_photos.length > 0) {
			for (i = 0; i < _photos.length; i++) {
				
				uplist['type'][k] = 'pic';
				uplist['url'][k] = _photos[i].src;
				k++;
			}	
		}
		var _video = $$('video_c_id').getElementsByTagName("video");
		if (_video.length > 0) {
			for (i = 0; i < _video.length; i++) {
				uplist['type'][k] = 'video';
				uplist['url'][k] = _video[i].src;
				k++;
			}
		}
		//alert(JSON.stringify(uplist));
		//return false;
		
		setStorJson('talk_ask_uplist',uplist);
		

		
		uexXmlHttpMgr.onData = function(opId, status, data){
			uexWindow.closeToast();
			status = true;
			if (status == 1) {
				data = JSON.parse(data);
				uexXmlHttpMgr.close(opId);
				if (data['success'] == 'NOTLOGIN') {
					gologin();
				}else if (data['success'] == 'NODATA') {
					uexWindow.toast("0", "5", '参数不能为空', 1000);
				}else if (data['success'] == 'OK') {
					localStorage['talk_ask_id']=data['id'];
					uexWindow.evaluatePopoverScript('talk','content','ok_ask()');
					uexWindow.evaluateScript('talk_ask',0,'uexWindow.close(0)');
				}else {
					uexWindow.toast("0", "5", '发布失败', 1000);
				}
			}else if (status == -1) {
				uexXmlHttpMgr.close(opId);
				uexWindow.toast("0", "5", '提交超时', 1000);
			}
		}
		
		
		
		var url = app_path+'index.php?m=iappTalk&c=app&a=talkadd&userid='+localStorage['u_id']+'&acctoken='+localStorage['u_acctoken'];
		uexXmlHttpMgr.open(1,'post',url,"8000");
		uexXmlHttpMgr.setPostData(1,'0','content',content);
		if(address!=''){
			uexXmlHttpMgr.setPostData(1,'0','address',address);
		}
		for(var item in Sele){
			if(Sele[item]){				
  				uexXmlHttpMgr.setPostData(1,'0',item,'true');
			}
		}
		
		uexXmlHttpMgr.send(1);
		uexWindow.toast(1, 5, '提交中...', 0);  
	}
	
	function backrecord(){
		if(!isstart){
			uexAudio.startBackgroundRecord(1);
			isstart = true;
			$$("backrecord").innerHTML = '录音中...';
			$$("backrecordv").innerHTML = '正在录音...';
		}else{
			isstart = false;
			$$("backrecord").innerHTML = '录音完成';
			$$("backrecordv").innerHTML = '录音完成,试听';
			
			uexAudio.stopBackgroundRecord()
			uexAudio.cbBackgroundRecord = function(opId, dataType, data){
				if (dataType == 0) {
					localStorage['talk_ask_voice']=data;
				}
			}
		}
	}
		
	function printobj(obj){
		var msg = '';
		for (var item in obj) {
			msg += item + ":" + obj[item]+'\n';
		}
		alert(msg);
	}
	
	
	function getadds(){
		
		if (isadds) {
			isadds = false;
			$$('address').innerHTML = '地址获取中';
			
			uexLocation.onChange = function(inLat, inLog){
				
				uexLocation.cbGetAddress = function(opCode, dataType, data){
					if (dataType == 0) {
						$$('address').innerHTML = data;
						localStorage['talk_ask_address'] = data;
						isadds = true;
						uexLocation.closeLocation();
					}
				};
				uexLocation.getAddress(inLat, inLog);
				
			}
			uexLocation.openLocation();
		}else{
			$$('address').innerHTML = '已经取消显示地址';
			localStorage['talk_ask_address'] ='';
		}
	}
	
	function share(t){
		if (localStorage[t + '_connectid']) {
			if (Sele[t] == true) {
				$$(t).className = '';
				Sele[t] = false;
			}else{
				$$(t).className = 'act';
				Sele[t] = true;
			}
		}else{
			uexWindow.toast("0", "5", '请先绑定分享账号', 3000);
			uexWindow.open('user_bind', '0', 'user_bind.html', 4, '', '', 0);
		}
	}
	
	/*
	var c2;
	c2=new cursorControl(document.getElementById('editdiv'));
	phiz('phiz_c');
	function fn2(str){
		c2.insertText(str);
	};
	*/

	window.uexOnload=function(type){
		if (!type) {
			localStorage['talk_ask_photos']='';
			localStorage['talk_ask_voice']='';
			localStorage['talk_ask_address']='';
			getadds();
		}
	}
	</script>
</html>